package com.iatinspur.dubbo.test;

import com.iatinspur.dubbo.factory.GenericServiceFactory;
import org.apache.dubbo.common.stream.StreamObserver;
import org.apache.dubbo.remoting.exchange.Response;
import org.apache.dubbo.rpc.service.GenericService;
import org.junit.jupiter.api.Test;
import java.io.Serializable;


/**
 * dubbo泛化版的流式调用 还想不是很支持
 */
public class TripleStreamDoProvider implements Serializable {

    /**
     *
     */
    @Test
    public  void doDubbo() {

    }

    /**
     *
     */
    @Test
    public  void doNacos() {
        GenericService service= GenericServiceFactory.getNacosService("com.iatinspur.dubbo.service.ProviderStreamService","1.0.0","tri");

        service.$invokeAsync("dubboServerStream",new String[]{String.class.getName(),StreamObserver.class.getName()},new Object[]{"黄剑",new MyStreamObserver() });
    }



    @Test
    public  void doZookeeper() {
        GenericService service= GenericServiceFactory.getZookeeperService("com.iatinspur.dubbo.service.ProviderStreamService","1.0.0","tri");
        service.$invokeAsync("dubboServerStream",new String[]{String.class.getName(), StreamObserver.class.getName()},new Object[]{"黄剑", new MyStreamObserver2()});
    }


    public static class MyStreamObserver implements StreamObserver<String>, Serializable {

        @Override
        public void onNext(String data) {
            System.err.println(data);
        }

        @Override
        public void onError(Throwable throwable) {

        }
        @Override
        public void onCompleted() {
            System.err.println("完毕");
        }

    }


    public static class MyStreamObserver1 implements StreamObserver<byte[]>, Serializable {

        @Override
        public void onNext(byte[] data) {
            System.err.println(data);
        }

        @Override
        public void onError(Throwable throwable) {

        }
        @Override
        public void onCompleted() {
            System.err.println("完毕");
        }


    }


    public static class MyStreamObserver2 implements StreamObserver<Response>, Serializable {

        @Override
        public void onNext(Response data) {
            System.err.println(data);
        }

        @Override
        public void onError(Throwable throwable) {

        }
        @Override
        public void onCompleted() {
            System.err.println("完毕");
        }


    }


}
